<?php
header("Access-Control-Allow-origin:*");
$ukey=$_POST["ukey"];
 //0 全部 1待处理    -99无效   99 有效
$type=@$_POST["step"] ? $_POST["step"] :0;
$arr=[];

$page = $_POST["page"] ? $_POST["page"] : 1;
$pagesize = $_POST["pagesize"] ? $_POST["pagesize"] : 20;
$arr = [];
$resArr = [];
$start = ($page - 1) * $pagesize + 1;
$end = $page * $pagesize;

if ($page == 5) {
    $end = $page * $pagesize - 5;
}

$randon=1;
$arrRand=array(-99,1,99);

function getStepname($number){
	if($number==-99){
      return "失效";
	}elseif ($number==1) {
			 return "待处理";
	}elseif($number==99){
 		return "有效";
	}
}


if(!$ukey){
	$arr["code"]=308;
	$arr["msg"]="请您先登录！";
	$arr["data"]=array();
}else{
	$arr["code"]=200;
	

	$reports=array();
	//邀请人是自己
	
	if($type==0 ||!$type){
		if(!!$randon){
			for ($i = $start; $i <= $end; $i++) {
				$rd=mt_rand(0,2);
		        $reports[] = array(
		        	"id"=>$i,
		            "realname" => "某某".$i,
		            "mobile"=>"18559160494",
		            "step"=>$arrRand[$rd],
		            "stepname"=>getStepname($arrRand[$rd]),
		            "origin" =>mt_rand(0,1)==0 ? "自带客" :"团队带客 (traic > 谢*尔)",
		            "reportno"=>$i,
		            "time"=>"2018-10-30 18:46",
		        );
		    }
		}
	}elseif($type==1){//待处理
		if(!!$randon){
			for ($i = $start; $i <= $end; $i++) {
		        $reports[] = array(
		        	"id"=>$i,
		            "realname" => "某某待处理-".$i,
		            "mobile"=>"18559160494",
		            "step"=>1,
		            "stepname"=>getStepname(1),
		            "origin" =>mt_rand(0,1)==0 ? "自带客" :"团队带客 (traic > 谢*尔)",
		            "reportno"=>$i,
		            "time"=>"2018-10-30 18:46",
		        );
		    }
		}
	}
	elseif($type==-99){//失效
		if(!!$randon){
			for ($i = $start; $i <= $end; $i++) {
		        $reports[] = array(
		        	"id"=>$i,
		            "realname" => "某某失效-".$i,
		            "mobile"=>"18559160494",
		            "step"=>-99,
		            "stepname"=>getStepname(-99),
		            "origin" =>mt_rand(0,1)==0 ? "自带客" :"团队带客 (traic > 谢*尔)",
		            "reportno"=>$i,
		            "time"=>"2018-10-30 18:46",
		        );
		    }
		}
	}
	elseif($type==99){//有效
		if(!!$randon){
			for ($i = $start; $i <= $end; $i++) {
		        $reports[] = array(
		        	"id"=>$i,
		            "realname" => "某某有效".$i,
		            "mobile"=>"18559160494",
		            "step"=>99,
		            "stepname"=>getStepname(99),
		            "origin" =>mt_rand(0,1)==0 ? "自带客" :"团队带客 (traic > 谢*尔)",
		            "reportno"=>$i,
		            "time"=>"2018-10-30 18:46",
		        );
		    }
		}
	}
	$arr["data"]["reports"]=$reports;	
}

echo json_encode($arr);
?>